home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Entertainment / MacMud / Mud 4.0 / make_func.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-16  |  21.8 KB  |  838 lines  |  [TEXT/????]

  1. #ifndef lint
  2. char yysccsid[] = "@(#)yaccpar    1.4 (Berkeley) 02/25/90";
  3. #endif
  4. #line 2 "make_func.y"
  5. #include <stdio.h>
  6. #include <ctype.h>
  7. #include <string.h>
  8. #include <fcntl.h>
  9. #include "lint.h"
  10. #include "config.h"
  11.  
  12. #undef open
  13. #undef fopen
  14.  
  15. #ifndef mac
  16. #define FUNC_SPEC     "make list_funcs"
  17. #else
  18. #undef fopen
  19. #define FUNC_SPEC    "list_funcs"
  20. #endif
  21. #define FUNC_TOKENS     "efun_tokens.y"
  22. #define PRE_LANG        "prelang.y"
  23. #define POST_LANG       "postlang.y"
  24. #define THE_LANG        "lang.y"
  25. #define BUFSIZ         1024
  26. #define NELEMS(arr)     (sizeof arr / sizeof arr[0])
  27.  
  28. #define MAX_FUNC      2048  /* If we need more than this we're in trouble! */
  29. int num_buff;
  30. /* For quick sort purposes : */
  31. char *key[MAX_FUNC], *buf[MAX_FUNC], has_token[MAX_FUNC];
  32.  
  33. int min_arg = -1, limit_max = 0;
  34.  
  35. /*
  36.  * arg_types is the types of all arguments. A 0 is used as a delimiter,
  37.  * marking next argument. An argument can have several types.
  38.  */
  39. int arg_types[200], last_current_type;
  40. /*
  41.  * Store the types of the current efun. They will be copied into the
  42.  * arg_types list if they were not already there (to save memory).
  43.  */
  44. #undef MAX_LOCAL
  45. #define MAX_LOCAL 20
  46. int curr_arg_types[MAX_LOCAL], curr_arg_type_size;
  47.  
  48. void yyerror PROT((char *));
  49. int yylex();
  50. int yyparse();
  51. int ungetc PROT((int c, FILE *f));
  52. char *type_str PROT((int)), *etype PROT((int)), *etype1 PROT((int)),
  53.    *ctype PROT((int));
  54. #ifndef toupper
  55. int toupper PROT((int));
  56. #endif
  57.  
  58. void fatal(str)
  59.     char *str;
  60. {
  61.     fprintf(stderr, "%s", str);
  62.     exit(1);
  63. }
  64.  
  65. #line 63 "make_func.y"
  66. typedef union {
  67.     int number;
  68.     char *string;
  69. } YYSTYPE;
  70. #line 71 "y.tab.c"
  71. #define ID 257
  72. #define VOID 258
  73. #define INT 259
  74. #define STRING 260
  75. #define OBJECT 261
  76. #define MIXED 262
  77. #define UNKNOWN 263
  78. #define MAPPING 264
  79. #define DEFAULT 265
  80. #define YYERRCODE 256
  81. short yylhs[] = {                                        -1,
  82.     0,    0,    7,    7,    8,    8,    9,    1,    1,    3,
  83.     3,    3,    3,    3,    3,    3,    2,    2,    2,    6,
  84.     5,    4,    4,    4,
  85. };
  86. short yylen[] = {                                         2,
  87.     0,    2,    1,    0,    3,    0,    8,    1,    2,    1,
  88.     1,    1,    1,    1,    1,    1,    0,    1,    3,    1,
  89.     1,    1,    3,    3,
  90. };
  91. short yydefred[] = {                                      1,
  92.     0,   10,   11,   12,   15,   13,   14,   16,    0,    0,
  93.     2,    0,    9,    3,    0,    0,    0,   21,    0,    0,
  94.    22,   18,    0,    0,    0,    0,    0,   24,    0,   19,
  95.     0,   23,    5,    7,
  96. };
  97. short yydgoto[] = {                                       1,
  98.    18,   19,   10,   20,   21,   22,   15,   26,   11,
  99. };
  100. short yysindex[] = {                                      0,
  101.  -251,    0,    0,    0,    0,    0,    0,    0, -243,  -27,
  102.     0, -240,    0,    0,  -22,  -30,  -26,    0,  -38, -105,
  103.     0,    0,  -25,  -36,  -30,  -18, -251,    0, -233,    0,
  104.   -34,    0,    0,    0,
  105. };
  106. short yyrindex[] = {                                      0,
  107.     0,    0,    0,    0,    0,    0,    0,    0,    0,  -41,
  108.     0,  -14,    0,    0,    0,  -40,    0,    0,  -13,  -39,
  109.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  110.     0,    0,    0,    0,
  111. };
  112. short yygindex[] = {                                      0,
  113.    26,    0,    0,    0,    2,    5,    0,    0,    0,
  114. };
  115. #define YYTABLESIZE 234
  116. short yytable[] = {                                       8,
  117.    17,   20,    8,   17,   20,   25,    2,    3,    4,    5,
  118.     6,    7,    8,   12,   13,   17,   14,   16,   27,   23,
  119.    28,   29,   31,   33,   34,    4,    9,    6,   32,   30,
  120.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  121.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  122.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  123.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  124.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  125.     0,    0,    8,    0,    0,    0,    0,    0,    0,    0,
  126.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  127.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  128.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  129.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  130.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  131.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  132.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  133.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  134.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  135.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  136.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  137.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  138.     0,    0,    0,    0,    0,    8,    0,    0,    0,    0,
  139.     0,    0,    0,    8,   17,   20,   24,    2,    3,    4,
  140.     5,    6,    7,    8,
  141. };
  142. short yycheck[] = {                                      41,
  143.    41,   41,   44,   44,   44,   44,  258,  259,  260,  261,
  144.   262,  263,  264,  257,   42,   46,  257,   40,  124,   46,
  145.    46,   58,   41,  257,   59,   40,    1,   41,   27,   25,
  146.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  147.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  148.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  149.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  150.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  151.    -1,   -1,  124,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  152.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  153.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  154.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  155.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  156.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  157.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  158.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  159.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  160.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  161.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  162.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  163.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  164.    -1,   -1,   -1,   -1,   -1,  257,   -1,   -1,   -1,   -1,
  165.    -1,   -1,   -1,  265,  265,  265,  265,  258,  259,  260,
  166.   261,  262,  263,  264,
  167. };
  168. #define YYFINAL 1
  169. #ifndef YYDEBUG
  170. #define YYDEBUG 0
  171. #endif
  172. #define YYMAXTOKEN 265
  173. #if YYDEBUG
  174. char *yyname[] = {
  175. "end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  176. 0,0,0,0,0,0,"'('","')'","'*'",0,"','",0,"'.'",0,0,0,0,0,0,0,0,0,0,0,"':'","';'",
  177. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  178. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'|'",0,0,0,0,0,0,0,0,0,0,0,0,0,
  179. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  180. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  181. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  182. "ID","VOID","INT","STRING","OBJECT","MIXED","UNKNOWN","MAPPING","DEFAULT",
  183. };
  184. char *yyrule[] = {
  185. "$accept : funcs",
  186. "funcs :",
  187. "funcs : funcs func",
  188. "optional_ID : ID",
  189. "optional_ID :",
  190. "optional_default : DEFAULT ':' ID",
  191. "optional_default :",
  192. "func : type ID optional_ID '(' arg_list optional_default ')' ';'",
  193. "type : basic",
  194. "type : basic '*'",
  195. "basic : VOID",
  196. "basic : INT",
  197. "basic : STRING",
  198. "basic : MIXED",
  199. "basic : UNKNOWN",
  200. "basic : OBJECT",
  201. "basic : MAPPING",
  202. "arg_list :",
  203. "arg_list : typel2",
  204. "arg_list : arg_list ',' typel2",
  205. "typel2 : typel",
  206. "arg_type : type",
  207. "typel : arg_type",
  208. "typel : typel '|' arg_type",
  209. "typel : '.' '.' '.'",
  210. };
  211. #endif
  212. #define yyclearin (yychar=(-1))
  213. #define yyerrok (yyerrflag=0)
  214. #ifndef YYSTACKSIZE
  215. #ifdef YYMAXDEPTH
  216. #define YYSTACKSIZE YYMAXDEPTH
  217. #else
  218. #define YYSTACKSIZE 300
  219. #endif
  220. #endif
  221. int yydebug;
  222. int yynerrs;
  223. int yyerrflag;
  224. int yychar;
  225. short *yyssp;
  226. YYSTYPE *yyvsp;
  227. YYSTYPE yyval;
  228. YYSTYPE yylval;
  229. #define yystacksize YYSTACKSIZE
  230. short yyss[YYSTACKSIZE];
  231. YYSTYPE yyvs[YYSTACKSIZE];
  232. #line 175 "make_func.y"
  233.  
  234. struct type {
  235.     char *name;
  236.     int num;
  237. } types[] = {
  238. { "void", VOID },
  239. { "int", INT },
  240. { "string", STRING },
  241. { "object", OBJECT },
  242. { "mixed", MIXED },
  243. { "unknown", UNKNOWN },
  244. { "mapping", MAPPING }
  245. };
  246.  
  247. FILE *f;
  248. int current_line = 1;
  249.  
  250. int main(argc, argv)
  251.     int argc;
  252.     char **argv;
  253. {
  254.     int i, fdr, fdw;
  255.     char buffer[BUFSIZ + 1];
  256.  
  257. #ifdef mac
  258.     #pragma unused(argc,argv)
  259. #endif
  260.  
  261. #ifndef mac
  262.     if ((f = (FILE *)popen(FUNC_SPEC, "r")) == NULL) {
  263. #else
  264.     if ((f = (FILE *)fopen(FUNC_SPEC, "r")) == NULL) {
  265. #endif
  266.     perror(FUNC_SPEC);
  267.     exit(1);
  268.     }
  269.     yyparse();
  270.     /* Now sort the main_list */
  271.     for (i = 0; i < num_buff; i++) {
  272.        int j;
  273.        for (j = 0; j < i; j++)
  274.        if (strcmp(key[i], key[j]) < 0) {
  275.           char *tmp;
  276.           int tmpi;
  277.           tmp = key[i]; key[i] = key[j]; key[j] = tmp;
  278.           tmp = buf[i]; buf[i] = buf[j]; buf[j] = tmp;
  279.           tmpi = has_token[i];
  280.           has_token[i] = has_token[j]; has_token[j] = tmpi;
  281.            }
  282.     }
  283.     /* Now display it... */
  284.     printf("{\n");
  285.     for (i = 0; i < num_buff; i++)
  286.        printf("%s", buf[i]);
  287.     printf("\n};\nint efun_arg_types[] = {\n");
  288.     for (i=0; i < last_current_type; i++) {
  289.     if (arg_types[i] == 0)
  290.         printf("0,\n");
  291.     else
  292.         printf("%s,", ctype(arg_types[i]));
  293.     }
  294.     printf("};\n");
  295. #ifndef mac
  296.     pclose(f);
  297. #else
  298.     fclose(f);
  299. #endif
  300.     /*
  301.      * Write all the tokens out.  Do this by copying the
  302.      * pre-include portion of lang.y to lang.y, appending
  303.      * this information, then appending the post-include
  304.      * portion of lang.y.  It's done this way because I don't
  305.      * know how to get YACC to #include %token files.  *grin*
  306.      */
  307.     if ((fdr = open(PRE_LANG, O_RDONLY)) < 0) {
  308.        perror(PRE_LANG);
  309.        exit(1);
  310.     }
  311.     unlink(THE_LANG);
  312. #ifndef mac
  313.     if ((fdw = open(THE_LANG, O_CREAT | O_WRONLY, 0444)) < 0) {
  314. #else
  315.     if ((fdw = open(THE_LANG, O_CREAT | O_WRONLY)) < 0) {
  316. #endif
  317.        perror(THE_LANG);
  318.        exit(1);
  319.     }
  320.     while (i = read(fdr, buffer, BUFSIZ))
  321.        write(fdw, buffer, i);
  322.     close(fdr);
  323.     for (i = 0; i < num_buff; i++) {
  324.        if (has_token[i]) {
  325.           char *str;   /* It's okay to mung key[*] now */
  326.           for (str = key[i]; *str; str++)
  327.             if (islower(*str)) *str = toupper(*str);
  328.           sprintf(buffer, "%%token F_%s\n", key[i]);
  329.           write(fdw, buffer, strlen(buffer));
  330.        }
  331.     }
  332.     if ((fdr = open(POST_LANG, O_RDONLY)) < 0) {
  333.        perror(POST_LANG);
  334.        exit(1);
  335.     }
  336.     while (i = read(fdr, buffer, BUFSIZ))
  337.        write(fdw, buffer, i);
  338.     close(fdr), close(fdw);
  339.     return 0;
  340. }
  341.  
  342. void yyerror(str)
  343.     char *str;
  344. {
  345.     fprintf(stderr, "%s:%d: %s\n", FUNC_SPEC, current_line, str);
  346.     exit(1);
  347. }
  348.  
  349. int ident(c)
  350.     int c;
  351. {
  352.     char buff[100];
  353.     int len, i;
  354.  
  355.     for (len=0; isalnum(c) || c == '_'; c = getc(f)) {
  356.     buff[len++] = c;
  357.     if (len + 1 >= sizeof buff)
  358.         fatal("Local buffer in ident() too small!\n");
  359.     if (len == sizeof buff - 1) {
  360.         yyerror("Too long indentifier");
  361.         break;
  362.     }
  363.     }
  364.     (void)ungetc(c, f);
  365.     buff[len] = '\0';
  366.     for (i=0; i < NELEMS(types); i++) {
  367.     if (strcmp(buff, types[i].name) == 0) {
  368.         yylval.number = types[i].num;
  369.         return types[i].num;
  370.     }
  371.     }
  372.     if (strcmp(buff, "default") == 0)
  373.     return DEFAULT;
  374.     yylval.string = malloc(strlen(buff)+1);
  375.     strcpy(yylval.string, buff);
  376.     return ID;
  377. }
  378.  
  379. char *type_str(n)
  380.     int n;
  381. {
  382.     int i, type = n & 0xffff;
  383.  
  384.     for (i=0; i < NELEMS(types); i++) {
  385.     if (types[i].num == type) {
  386.         if (n & 0x10000) {
  387.         static char buff[100];
  388.         if (strlen(types[i].name) + 3 > sizeof buff)
  389.             fatal("Local buffer too small in type_str()!\n");
  390.         sprintf(buff, "%s *", types[i].name);
  391.         return buff;
  392.         }
  393.         return types[i].name;
  394.     }
  395.     }
  396.     return "What ?";
  397. }
  398.  
  399. int yylex1() {
  400.     register int c;
  401.     
  402.     for(;;) {
  403.     switch(c = getc(f)) {
  404.     case ' ':
  405.     case '\t':
  406.         continue;
  407.     case '#':
  408.     {
  409. #ifdef sun /* no prototype in <stdio.h> *sigh* */
  410.         extern int fscanf PROT((FILE *, char *, ...));
  411. #endif
  412.         int line;
  413.         char file[2048]; /* does any operating system support
  414.                 longer pathnames? */
  415.         if ( fscanf(f,"%d \"%s\"",&line,file ) == 2 )
  416.         current_line = line;
  417.         while(c != '\n' && c != EOF)
  418.         c = getc(f);
  419.         current_line++;
  420.         continue;
  421.     }
  422.     case '\n':
  423.         current_line++;
  424.         continue;
  425.     case EOF:
  426.         return -1;
  427.     default:
  428.         if (isalpha(c))
  429.         return ident(c);
  430.         return c;
  431.     }
  432.     }
  433. }
  434.  
  435. int yylex() {
  436.     return yylex1();
  437. }
  438.  
  439. char *etype1(n)
  440.     int n;
  441. {
  442.     if (n & 0x10000)
  443.     return "T_POINTER";
  444.     switch(n) {
  445.     case INT:
  446.     return "T_NUMBER";
  447.     case OBJECT:
  448.     return "T_OBJECT";
  449.     case STRING:
  450.     return "T_STRING";
  451.     case MAPPING:
  452.     return "T_MAPPING";
  453.     case MIXED:
  454.     return "0";    /* 0 means any type */
  455.     default:
  456.     yyerror("Illegal type for argument");
  457.     }
  458.     return "What ?";
  459. }
  460.  
  461. char *etype(n)
  462.     int n;
  463. {
  464.     int i;
  465.     int local_size = 100;
  466.     char *buff = malloc(local_size);
  467.  
  468.     for (i=0; i < curr_arg_type_size; i++) {
  469.     if (n == 0)
  470.         break;
  471.     if (curr_arg_types[i] == 0)
  472.         n--;
  473.     }
  474.     if (i == curr_arg_type_size || curr_arg_types[i] == 0)
  475.     return "0";
  476.     buff[0] = '\0';
  477.     for(; curr_arg_types[i] != 0; i++) {
  478.     char *p;
  479.     if (curr_arg_types[i] == VOID)
  480.         continue;
  481.     if (buff[0] != '\0')
  482.         strcat(buff, "|");
  483.     p = etype1(curr_arg_types[i]);
  484.     /*
  485.      * The number 2 below is to include the zero-byte and the next
  486.      * '|' (which may not come).
  487.      */
  488.     if (strlen(p) + strlen(buff) + 2 > local_size) {
  489.         fprintf(stderr, "Buffer overflow!\n");
  490.         exit(1);
  491.     }
  492.     strcat(buff, etype1(curr_arg_types[i]));
  493.     }
  494.     return buff;
  495. }
  496.  
  497. char *ctype(n)
  498.     int n;
  499. {
  500.     static char buff[100];    /* 100 is such a comfortable size :-) */
  501.     char *p;
  502.  
  503.     if (n & 0x10000)
  504.     strcpy(buff, "TYPE_MOD_POINTER|");
  505.     else
  506.     buff[0] = '\0';
  507.     n &= ~0x10000;
  508.     switch(n) {
  509.     case VOID: p = "TYPE_VOID"; break;
  510.     case STRING: p = "TYPE_STRING"; break;
  511.     case INT: p = "TYPE_NUMBER"; break;
  512.     case OBJECT: p = "TYPE_OBJECT"; break;
  513.     case MIXED: p = "TYPE_ANY"; break;
  514.     case MAPPING: p = "TYPE_MAPPING"; break;
  515.     case UNKNOWN: p = "TYPE_UNKNOWN"; break;
  516.     default: yyerror("Bad type!");
  517.     }
  518.     strcat(buff, p);
  519.     if (strlen(buff) + 1 > sizeof buff)
  520.     fatal("Local buffer overwritten in ctype()");
  521.     return buff;
  522. }
  523. #line 524 "y.tab.c"
  524. #define YYABORT goto yyabort
  525. #define YYACCEPT goto yyaccept
  526. #define YYERROR goto yyerrlab
  527. int
  528. yyparse()
  529. {
  530.     register int yym, yyn, yystate;
  531. #if YYDEBUG
  532.     register char *yys;
  533.     extern char *getenv();
  534.  
  535.     if (yys = getenv("YYDEBUG"))
  536.     {
  537.         yyn = *yys;
  538.         if (yyn >= '0' && yyn <= '9')
  539.             yydebug = yyn - '0';
  540.     }
  541. #endif
  542.  
  543.     yynerrs = 0;
  544.     yyerrflag = 0;
  545.     yychar = (-1);
  546.  
  547.     yyssp = yyss;
  548.     yyvsp = yyvs;
  549.     *yyssp = yystate = 0;
  550.  
  551. yyloop:
  552.     if (yyn = yydefred[yystate]) goto yyreduce;
  553.     if (yychar < 0)
  554.     {
  555.         if ((yychar = yylex()) < 0) yychar = 0;
  556. #if YYDEBUG
  557.         if (yydebug)
  558.         {
  559.             yys = 0;
  560.             if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
  561.             if (!yys) yys = "illegal-symbol";
  562.             printf("yydebug: state %d, reading %d (%s)\n", yystate,
  563.                     yychar, yys);
  564.         }
  565. #endif
  566.     }
  567.     if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
  568.             yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
  569.     {
  570. #if YYDEBUG
  571.         if (yydebug)
  572.             printf("yydebug: state %d, shifting to state %d\n",
  573.                     yystate, yytable[yyn]);
  574. #endif
  575.         if (yyssp >= yyss + yystacksize - 1)
  576.         {
  577.             goto yyoverflow;
  578.         }
  579.         *++yyssp = yystate = yytable[yyn];
  580.         *++yyvsp = yylval;
  581.         yychar = (-1);
  582.         if (yyerrflag > 0)  --yyerrflag;
  583.         goto yyloop;
  584.     }
  585.     if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
  586.             yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
  587.     {
  588.         yyn = yytable[yyn];
  589.         goto yyreduce;
  590.     }
  591.     if (yyerrflag) goto yyinrecovery;
  592. #ifdef lint
  593.     goto yynewerror;
  594. #endif
  595. yynewerror:
  596.     yyerror("syntax error");
  597. #ifdef lint
  598.     goto yyerrlab;
  599. #endif
  600. yyerrlab:
  601.     ++yynerrs;
  602. yyinrecovery:
  603.     if (yyerrflag < 3)
  604.     {
  605.         yyerrflag = 3;
  606.         for (;;)
  607.         {
  608.             if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
  609.                     yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
  610.             {
  611. #if YYDEBUG
  612.                 if (yydebug)
  613.                     printf("yydebug: state %d, error recovery shifting\
  614.  to state %d\n", *yyssp, yytable[yyn]);
  615. #endif
  616.                 if (yyssp >= yyss + yystacksize - 1)
  617.                 {
  618.                     goto yyoverflow;
  619.                 }
  620.                 *++yyssp = yystate = yytable[yyn];
  621.                 *++yyvsp = yylval;
  622.                 goto yyloop;
  623.             }
  624.             else
  625.             {
  626. #if YYDEBUG
  627.                 if (yydebug)
  628.                     printf("yydebug: error recovery discarding state %d\n",
  629.                             *yyssp);
  630. #endif
  631.                 if (yyssp <= yyss) goto yyabort;
  632.                 --yyssp;
  633.                 --yyvsp;
  634.             }
  635.         }
  636.     }
  637.     else
  638.     {
  639.         if (yychar == 0) goto yyabort;
  640. #if YYDEBUG
  641.         if (yydebug)
  642.         {
  643.             yys = 0;
  644.             if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
  645.             if (!yys) yys = "illegal-symbol";
  646.             printf("yydebug: state %d, error recovery discards token %d (%s)\n",
  647.                     yystate, yychar, yys);
  648.         }
  649. #endif
  650.         yychar = (-1);
  651.         goto yyloop;
  652.     }
  653. yyreduce:
  654. #if YYDEBUG
  655.     if (yydebug)
  656.         printf("yydebug: state %d, reducing by rule %d (%s)\n",
  657.                 yystate, yyn, yyrule[yyn]);
  658. #endif
  659.     yym = yylen[yyn];
  660.     yyval = yyvsp[1-yym];
  661.     switch (yyn)
  662.     {
  663. case 4:
  664. #line 83 "make_func.y"
  665. { yyval.string  = ""; }
  666. break;
  667. case 5:
  668. #line 85 "make_func.y"
  669. { yyval.string  = yyvsp[0].string ; }
  670. break;
  671. case 6:
  672. #line 85 "make_func.y"
  673. { yyval.string ="0"; }
  674. break;
  675. case 7:
  676. #line 88 "make_func.y"
  677. {
  678.     char buff[500];
  679.     char f_name[500];
  680.     int i;
  681.     if (min_arg == -1)
  682.         min_arg = yyvsp[-3].number ;
  683.     if (yyvsp[-5].string [0] == '\0') {
  684.         int len;
  685.         if (strlen(yyvsp[-6].string ) + 1 + 2 > sizeof f_name)
  686.         fatal("A local buffer was too small!(1)\n");
  687.         sprintf(f_name, "F_%s", yyvsp[-6].string );
  688.         len = strlen(f_name);
  689.         for (i=0; i < len; i++) {
  690.         if (islower(f_name[i]))
  691.             f_name[i] = toupper(f_name[i]);
  692.         }
  693.         has_token[num_buff]=1;
  694.     } else {
  695.         if (strlen(yyvsp[-5].string ) + 1 > sizeof f_name)
  696.         fatal("A local buffer was too small(2)!\n");
  697.         strcpy(f_name, yyvsp[-5].string );
  698.         has_token[num_buff]=0;
  699.     }
  700.     for(i=0; i < last_current_type; i++) {
  701.         int j;
  702.         for (j = 0; j+i<last_current_type && j < curr_arg_type_size; j++)
  703.         {
  704.         if (curr_arg_types[j] != arg_types[i+j])
  705.             break;
  706.         }
  707.         if (j == curr_arg_type_size)
  708.         break;
  709.     }
  710.     if (i == last_current_type) {
  711.         int j;
  712.         for (j=0; j < curr_arg_type_size; j++) {
  713.         arg_types[last_current_type++] = curr_arg_types[j];
  714.         if (last_current_type == NELEMS(arg_types))
  715.             yyerror("Array 'arg_types' is too small");
  716.         }
  717.     }
  718.     sprintf(buff, "{\"%s\",%s,%d,%d,%s,%s,%s,%d,%s},\n",
  719.         yyvsp[-6].string , f_name, min_arg, limit_max ? -1 : yyvsp[-3].number , ctype(yyvsp[-7].number ),
  720.         etype(0), etype(1), i, yyvsp[-2].string );
  721.         if (strlen(buff) > sizeof buff)
  722.              fatal("Local buffer overwritten !\n");
  723.         key[num_buff] = (char *) malloc(strlen(yyvsp[-6].string ) + 1);
  724.     strcpy(key[num_buff], yyvsp[-6].string );
  725.     buf[num_buff] = (char *) malloc(strlen(buff) + 1);
  726.     strcpy(buf[num_buff], buff);
  727.         num_buff++;
  728.     min_arg = -1;
  729.     limit_max = 0;
  730.     curr_arg_type_size = 0;
  731.     }
  732. break;
  733. case 9:
  734. #line 144 "make_func.y"
  735. { yyval.number  = yyvsp[-1].number  | 0x10000; }
  736. break;
  737. case 17:
  738. #line 148 "make_func.y"
  739. { yyval.number  = 0; }
  740. break;
  741. case 18:
  742. #line 149 "make_func.y"
  743. { yyval.number  = 1; if (yyvsp[0].number ) min_arg = 0; }
  744. break;
  745. case 19:
  746. #line 150 "make_func.y"
  747. { yyval.number  = yyvsp[-2].number  + 1; if (yyvsp[0].number ) min_arg = yyval.number  - 1; }
  748. break;
  749. case 20:
  750. #line 153 "make_func.y"
  751. {
  752.     yyval.number  = yyvsp[0].number ;
  753.     curr_arg_types[curr_arg_type_size++] = 0;
  754.     if (curr_arg_type_size == NELEMS(curr_arg_types))
  755.         yyerror("Too many arguments");
  756.     }
  757. break;
  758. case 21:
  759. #line 161 "make_func.y"
  760. {
  761.     if (yyvsp[0].number  != VOID) {
  762.         curr_arg_types[curr_arg_type_size++] = yyvsp[0].number ;
  763.         if (curr_arg_type_size == NELEMS(curr_arg_types))
  764.         yyerror("Too many arguments");
  765.     }
  766.     yyval.number  = yyvsp[0].number ;
  767.     }
  768. break;
  769. case 22:
  770. #line 170 "make_func.y"
  771. { yyval.number  = (yyvsp[0].number  == VOID && min_arg == -1); }
  772. break;
  773. case 23:
  774. #line 171 "make_func.y"
  775. { yyval.number  = (min_arg == -1 && (yyvsp[-2].number  || yyvsp[0].number  == VOID));}
  776. break;
  777. case 24:
  778. #line 172 "make_func.y"
  779. { yyval.number  = min_arg == -1 ; limit_max = 1; }
  780. break;
  781. #line 782 "y.tab.c"
  782.     }
  783.     yyssp -= yym;
  784.     yystate = *yyssp;
  785.     yyvsp -= yym;
  786.     yym = yylhs[yyn];
  787.     if (yystate == 0 && yym == 0)
  788.     {
  789. #ifdef YYDEBUG
  790.         if (yydebug)
  791.             printf("yydebug: after reduction, shifting from state 0 to\
  792.  state %d\n", YYFINAL);
  793. #endif
  794.         yystate = YYFINAL;
  795.         *++yyssp = YYFINAL;
  796.         *++yyvsp = yyval;
  797.         if (yychar < 0)
  798.         {
  799.             if ((yychar = yylex()) < 0) yychar = 0;
  800. #if YYDEBUG
  801.             if (yydebug)
  802.             {
  803.                 yys = 0;
  804.                 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
  805.                 if (!yys) yys = "illegal-symbol";
  806.                 printf("yydebug: state %d, reading %d (%s)\n",
  807.                         YYFINAL, yychar, yys);
  808.             }
  809. #endif
  810.         }
  811.         if (yychar == 0) goto yyaccept;
  812.         goto yyloop;
  813.     }
  814.     if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
  815.             yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
  816.         yystate = yytable[yyn];
  817.     else
  818.         yystate = yydgoto[yym];
  819. #ifdef YYDEBUG
  820.     if (yydebug)
  821.         printf("yydebug: after reduction, shifting from state %d \
  822. to state %d\n", *yyssp, yystate);
  823. #endif
  824.     if (yyssp >= yyss + yystacksize - 1)
  825.     {
  826.         goto yyoverflow;
  827.     }
  828.     *++yyssp = yystate;
  829.     *++yyvsp = yyval;
  830.     goto yyloop;
  831. yyoverflow:
  832.     yyerror("yacc stack overflow");
  833. yyabort:
  834.     return (1);
  835. yyaccept:
  836.     return (0);
  837. }
  838.